<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
		<form id="fr">
			<input type="file" multiple="multiple" onchange="clean()" name="file"  id="file"/>
			<br />
			密码:<input type="text" name="pwd" id="pwd" autocomplete="off" placeholder="url后面加?pwd=密码"/>
			<br />
			<input type="button" value="上传文件" onclick="send()"  />
			
		</form>
		<div id="v"></div>
		
	<script src="js/jquery-3.4.1.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/layer/layer.js"></script>
	<script>
		var url="https://img.pexex.info:9008/upload";
		var div =document.getElementById("v");
		
		function clean(){
			div.innerHTML="";
		}
		
		function send(){
			f =new FormData(document.getElementById("fr"));
			var tit=document.title;
			if(document.getElementById("file").files.length<1){
				layer.msg("空的");
				return ;
			}
			tipfs=event.target;
			tipfs.disabled=true;
			$.ajax({
			        type : "POST",  
			        url : `${url}/uploadFiles`,  
			        data : f,
			        async: true,  
			        cache: false,  
			        contentType: false,  
			        processData: false,
					xhr:function(){                        
						myXhr = $.ajaxSettings.xhr();
						if(myXhr.upload){ // check if upload property exists
							myXhr.upload.addEventListener('progress',function(e){
								var loaded = e.loaded;                  //已经上传大小情况 
								var total = e.total;                      //附件总大小 
								var percent = Math.floor(100*loaded/total)+"%";     //已经上传的百分比  
								console.log("已经上传了："+percent);

								document.title=percent;
								tipfs.value=percent;
							}, false); // for handling the progress of the upload
						}
						return myXhr;
					},
			        success : function(msg) {  
						document.getElementById("file").value=null;
						console.log(msg);
						for (let i = 0; i < msg.length; i++) {
							msg[i];
							let p=document.createElement("p");
							p.innerHTML=`${msg[i].file_name}    :    ${url}/${msg[i].uid}`;
							div.appendChild(p);
						}
						document.title=tit;
						tipfs.disabled=false;
						tipfs.value="上传"
			        }  
			});
		}
		
	</script>
	</body>
</html>
